//************************************************************
//  Copyright (c)   
//	FileName	  : SC_it.c
//	Function	  : Interrupt Service Routine
//  Instructions  :  
//  Date          : 2022/03/03
// 	Version		  : V1.0002
//*************************************************************
/********************Includes************************************************************************/
#include "SC_it.h"
#include "..\Drivers\SCDriver_list.h"
#include "stdio.h"
#include "drv_sonsor_air.h"
#include "toolkit.h"
#include "filterCounter.h"
//#include "host_cmd.h"
#include "ringbuffer.h"
//#include "drv_iot.h"
#include "drv_iot_mj.h"
/**************************************Generated by EasyCodeCube*************************************/
//Forbid editing areas between the labels !!!

/*************************************.Generated by EasyCodeCube.************************************/
uint32_t xdata sysTick = 0;
uint32_t xdata keyTick = 0;
//uint32_t flag10S = 0;
//uint8_t  BTMCount_1S=0;
//uint32_t xdata BTMCount_1min = 0;
bit Uart0SendFlag = 0;
bit Uart0ReceiveFlag = 0;

bit Uart1SendFlag = 0;
bit Uart1ReceiveFlag = 0;

bit UartXSendFlag = 0;
bit UartXReceiveFlag = 0;

bit SecondFlag = 0;
bit BeepOnFlag = 0;

//extern uint32_t xdata countDownTime ;
extern uint32_t xdata countDownFlag ;


//extern bool xdata TimeWriteFlag;
// extern EVT_STATUS evt_Filter;
extern bool keyTick_ONOFF(void);


/* ring buffer data*/



void INT0Interrupt()		interrupt 0				
{
    TCON &= 0XFD;//Clear interrupt flag bit
    /*INT0_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*INT0_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*INT0Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*INT0Interrupt Flag Clear end*/
}
void Timer0Interrupt()		interrupt 1			   
{
    /*TIM0_it write here begin*/
    //Forbid editing areas between the labels !!!
    TIM0_Mode1SetReloadCounter(33536);
    /*TIM0_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<UserCodeStart>*//*<SinOne-Tag><15>*/
    /***User program***/
		sysTick++;
//		if(sysTick >= SYS_TIME_OUT){
//			sysTick = 0;
//		}
		if((sysTick % 1000) == 0)
		{
			SecondFlag=1;
		}
		if(keyTick_ONOFF() == TRUE)
		{
			keyTick++;
		}
    /*<UserCodeEnd>*//*<SinOne-Tag><15>*/
    /*<Generated by EasyCodeCube end>*/
    /*Timer0Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*Timer0Interrupt Flag Clear end*/		
}

uint32_t get_Systick(void)
{
    return sysTick;
}	

void INT1Interrupt()		interrupt 2		
{
    TCON &= 0XF7;//Clear interrupt flag bit
    /*INT1_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*INT1_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*INT1Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*INT1Interrupt Flag Clear end*/					
}
void Timer1Interrupt()		interrupt 3		
{
    /*TIM1_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*TIM1_it write here*/
		TIM1_Mode1SetReloadCounter(55936);		
		if(BeepOnFlag)
		P23=!P23;
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*Timer1Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*Timer1Interrupt Flag Clear end*/		
}
#if defined (SC92F742x) || defined (SC92F7490)
void SSI0Interrupt()		interrupt 4		
{
    /*SSI0_it write here begin*/
    /*SSI0_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*SSI0Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*SSI0Interrupt Flag Clear end*/		
}
#else
void UART0Interrupt()		interrupt 4		
{
//	if(US0CON0&0x02)    
//	{
//		US0CON0 &= 0xFE;
//		Uart0SendFlag = 1;
//	}
//	if((US0CON0&0x01))  //
//	{
//		US0CON0 &= 0xFD;
//		Uart0ReceiveFlag = 1;
//		//addToRingBuf(US0CON3);
//	}		
}
#endif
void Timer2Interrupt()		interrupt 5		
{
    /*TIM2_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*TIM2_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*Timer2Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    PWM_ClearFlagEX(PWM2_Type);
    
    /*Timer2Interrupt Flag Clear end*/		
}
void ADCInterrupt()			interrupt 6		
{
    /*ADC_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*ADC_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*ADCInterrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*ADCInterrupt Flag Clear end*/		
}
#if defined (SC92F854x) || defined (SC92F754x) ||defined  (SC92F844xB) || defined (SC92F744xB)||defined  (SC92F84Ax_2) || defined (SC92F74Ax_2)|| defined (SC92F846xB) \
|| defined (SC92F746xB) || defined (SC92F836xB) || defined (SC92F736xB) || defined (SC92F8003)||defined  (SC92F84Ax) || defined (SC92F74Ax) || defined  (SC92F83Ax) \
|| defined (SC92F73Ax) || defined (SC92F7003) || defined (SC92F740x) || defined (SC92FWxx) || defined (SC93F743x) || defined (SC93F833x) || defined (SC93F843x)\
|| defined (SC92F848x) || defined (SC92F748x)|| defined (SC92F859x) || defined (SC92F759x)
void SSIInterrupt()			interrupt 7		
{
    /*SSI_it write here begin*/
    /*SSI_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*SSIInterrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*SSIInterrupt Flag Clear end*/		
}
#elif defined (SC92F742x) || defined (SC92F7490)
void SSI1Interrupt()		interrupt 7		
{
    /*SSI1_it write here begin*/
    /*SSI1_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*SSI1Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*SSI1Interrupt Flag Clear end*/		
}
#else 
void USCI0Interrupt()			interrupt 7		
{
    /*USCI0_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*USCI0_it write here*/
	if(US0CON0&0x02)    
	{
		US0CON0 &= 0xFE;
		Uart0SendFlag = 1;
	}
	if((US0CON0&0x01))  //
	{
        US0CON0 &= 0xFD;
		Uart0ReceiveFlag = 1;
		addToRingBuf(US0CON3);
		//P04 =!P04; 
    //ringbuffer_write(US0CON3, &ringbuffer);
	}	
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*USCI0Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*USCI0Interrupt Flag Clear end*/	
}
#endif
void PWMInterrupt()			interrupt 8
{
    /*PWM_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*PWM_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*PWMInterrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    PWM_ClearFlagEX(PWM0_Type);
    PWM_ClearFaultDetectionFlagEX(PWM0_Type);
    
    /*PWMInterrupt Flag Clear end*/		
}

void BTMInterrupt()			interrupt 9
{

}

void INT2Interrupt()		interrupt 10
{	
    /*INT2_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*INT2_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*INT2Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*INT2Interrupt Flag Clear end*/		
}
void ACMPInterrupt()		interrupt 12
{
    /*ACMP_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*ACMP_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*ACMPInterrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*ACMPInterrupt Flag Clear end*/		
}
void Timer3Interrupt()		interrupt 13
{
    /*TIM3_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*TIM3_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*Timer3Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*Timer3Interrupt Flag Clear end*/		
}
void Timer4Interrupt()		interrupt 14
{
    /*TIM4_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*TIM4_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*Timer4Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*Timer4Interrupt Flag Clear end*/		
}
void USCI1Interrupt()		interrupt 15		
{	
    /*USCI1_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*USCI1_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*USCI1Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
		if(US1CON0 & 0x02)  //
		{
			US1CON0 &= 0xFE;
			Uart1SendFlag = 1;
		}
		if((US1CON0 & 0x01)) //
		{
			US1CON0 &= 0xFD;
			Uart1ReceiveFlag = 1;
			//usart_pm2d5_receive(USXCON3);
		}
		//sensor_air_data_receive(USXCON3);
		
    //USCI1_ClearFlag(USCI1_UART_FLAG_RI);
    //USCI1_ClearFlag(USCI1_UART_FLAG_TI);
    
    /*USCI1Interrupt Flag Clear end*/		
}
void USCI2Interrupt()		interrupt 16		
{	
    /*USCI2_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*USCI2_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*USCI2Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
  if(USXCON0 & 0x02)  //���ͱ�־λ�ж�
  {
    USXCON0 &= 0xFE;
    UartXSendFlag = 1;
  }
  if((USXCON0 & 0x01)) //���ձ�־λ�ж�
  {
    USXCON0 &= 0xFD;
    UartXReceiveFlag = 1;
		usart_pm2d5_receive(USXCON3);
  }
    //USCI2_ClearFlag(USCI2_UART_FLAG_TI);
    
    /*USCI2Interrupt Flag Clear end*/		
}
void USCI3Interrupt()		interrupt 17		
{
    /*USCI3_it write here begin*/
    //Forbid editing areas between the labels !!!
    /*USCI3_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*USCI3Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*USCI3Interrupt Flag Clear end*/		
}
void USCI4Interrupt()		interrupt 18		
{
    /*USCI4_it write here begin*/
    /*USCI4_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*USCI4Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*USCI4Interrupt Flag Clear end*/		
}
void USCI5Interrupt()		interrupt 19		
{
    /*USCI5_it write here begin*/	
    /*USCI5_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*USCI5Interrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*USCI5Interrupt Flag Clear end*/		
}
void LPDInterrupt()		interrupt 22		
{
    /*LPD_it write here begin*/
    /*LPD_it write here*/
    /*<Generated by EasyCodeCube begin>*/
    /*<Generated by EasyCodeCube end>*/
    /*LPDInterrupt Flag Clear begin*/
    //Forbid editing areas between the labels !!!
    /*LPDInterrupt Flag Clear end*/		
}
